<?php
  $link = mysql_connect('', 'admin_xbq', 'nihao')
      or die('Could not connect: ' . mysql_error());
  //echo "Connected successfully\n";
  //echo '<br />';
  echo "<h1>List of institute and faculty</h1>";

  $query = "use test";
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  if (isset($_GET['id'])) {
    //here should be more! should delete all staff rooms, teachers and their files in db!
    $sql = "delete from department where department.depart_ID=".$_GET['id'];
    mysql_query($sql) or die('Query failed: ' . mysql_error());
  }
  $query = "select * from department;";
  $result = mysql_query($query) or die('Query failed: ' . mysql_error());
?>

<div  align="center">
  <table class="style2" >
    <tr>
      <th>ID</th>
      <th>Name of department</th>
      <th>Delete</th>
      <th>Edit</th>
    </tr>

<?php
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
      echo "<tr>\n\t<td>";
      echo $line['depart_ID'];
      echo "</td>\n<td>";
      echo "<a href=\"show_staffroom.php?d_id=";
      echo $line['depart_ID'];
      echo"\">".$line['d_full_name']."</a>";
      echo "</td><td><a Onclick=\"if(!confirm('Do you want to delete?')) return false;\" href=\"";
      echo $_SERVER['PHP_SELF'].'?id='.$line['depart_ID']; 
      echo "\">delete</a></td><td><a href=\"edit_depart.php?d_id=";
      echo $line['depart_ID'];
      echo "\">edit</a></td>\n</tr>\n";
  }
?>

    <tr>
      <td></td><td></td><td></td><td><a href="add_depart.php">Add</a></td>
    </tr>
  </table>
</div>
<br /><br />
  
<?php
  mysql_free_result($result);
  
  mysql_close($link);
?>
